-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typing for DataArray/Dataset #2929
Conversation
Hello @crusaderky! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2019-06-25 18:14:47 UTC |
One of the many reasons why I'm strongly against generic Hashables instead of strings is that I expect user code all over the world to have string-specific functions and methods applied to variable names and dimensions.
The above will produce an error in mypy, and the user will be forced to either disable the test or verbosely convince mypy with a |
Thanks @crusaderky , this looks great! Re:
Curious on others' thoughts. I would vote to allow |
Conflicts: xarray/core/dataarray.py
DataArray finished; unit tests (hopefully) successful. Will now move to Dataset. |
@crusaderky let's discuss that over in #2292. For now, I would try to defer making a decision on non-string dimension/variable names, even though that means we will have less informative type annotations. |
# Conflicts: # xarray/core/dataarray.py # xarray/core/dataset.py # xarray/tests/__init__.py
@crusaderky I finished this off as best I could. Tests pass though needs a review. Here's the code: https://github.com/max-sixty/xarray/tree/annotations (I tried pasting a patch, but I my git-fu isn't enough to exclude all the master code given there's a merge commit in there) |
@max-sixty thanks for the work! I'll go through it ASAP |
@max-sixty I merged your branch in and did some tweaks to the OrderedDict's. |
- mapping {coord name: DataArray} | ||
- mapping {coord name: Variable} | ||
- mapping {coord name: (dimension name, array-like)} | ||
- mapping {coord name: (tuple of dimension names, array-like)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Great, thanks @crusaderky ! Let me know if I can do anything to help! |
Just fixed some more merge conflicts over at https://github.com/max-sixty/xarray/tree/annotations. Thoughts on merging this now and continuing off master? |
+1 else the merge conflicts will just pile up. |
Sorry I didn't have time last week - I'll try merging into the pr ASAP. I'm in favour of merging to mainline too |
Cool, I think it should be a straight fast-forward merge from my branch to yours, and then an easy merge to master |
Great, I've resolved those comments @shoyer , thanks: https://github.com/max-sixty/xarray/tree/annotations @crusaderky we should be ready to go - maybe take a glance over to ensure you're happy. I added a whatsnew with both of us - hope that's OK |
@max-sixty do you want to push those changes to @crusaderky's branch? As a maintainer for xarray, I think you should have push permissions. |
Ah it works! Didn't know permissions transferred to forks. @crusaderky hope that's OK, not wanting to step on your toes here... |
xarray/core/dataarray.py
Outdated
attrs=None, encoding=None, indexes=None, fastpath=False): | ||
def __init__(self, data: Any, | ||
coords: Union[ | ||
Sequence[Tuple[Hashable, Any]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still not quite right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Erm, in the latest it's just Tuple
, is that OK? (I think maybe I pushed an older one first and you looked over that)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tuple
should be fine, but it looks like that commit isn't on this branch yet
xarray/core/dataset.py
Outdated
data_vars: Optional[Mapping[Hashable, Union[ | ||
'DataArray', Variable, | ||
Tuple[Hashable, Any], | ||
Tuple[Tuple[Hashable, ...], Any]]]] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one also can handle any tuples args
that you can use like Variable(*args)
(maybe we could define a VariableArgs
alias of some sort?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I added a comment re VariableArgs, def would be good to move some of these long definitions into a single place (but if you're OK with leaving until the next PR let's do that)
By the way, I think I can write a script based on pep8speaks that writes/updates GitHub comments from within from Travis or Azure Pipelines. We could use that for surfacing mypy results in pull requests. I will probably give that a try over the next few days.... |
That would be v cool. I'm kinda surprised something like pep8speaks doesn't do this already tbh... |
I was considering adding this into pep8speaks, but I think this fundamentally incompatible with pep8speak's design. It runs a handful of pre-specified linters, without actually installing/running user code. But something like mypy needs to actually have xarray and its dependencies installed to work. |
Yes, good point. I haven't spent much time with the GitHub Checks, but potentially could be a good fit - one issue with the simpler "Update the comment" model is that it doesn't encode to GH whether it's safe to merge, so projects need to duplicate the test in CI |
(AppVeyor fail looks unrelated) |
Thanks @max-sixty and @crusaderky ! |
Thanks @crusaderky ! |
Status:
"Mapping[...]" has no attribute "copy"
. This is due to the fact that I can't see a way to usetyping.OrderedDict
without breaking compatibility with python < 3.7.2.@shoyer any early feedback is appreciated